package com.fjec.gateway.config;

import com.fjec.common.eventbus.LogSubscribe;
import com.fjec.common.eventbus.SubscriberExceptionHandlerImpl;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;

//@Configuration
public class EventBusConfig {

    private String busName = "AppEventBus";

    private int threadSize = 10;

    @Bean
    public EventBus registerEventBus(LogSubscribe logSubscribe) {
        AsyncEventBus eventBus = new AsyncEventBus( Executors.newFixedThreadPool(threadSize),
                new SubscriberExceptionHandlerImpl());
        eventBus.register(logSubscribe);
        return eventBus;
    }

    @Bean
    public LogSubscribe logSubscribe() {
        return new LogSubscribe();
    }

}
